package com.assessment.util;

import java.io.File;  
import java.io.FileInputStream;  
import java.io.IOException;  
import java.util.ArrayList;
import java.util.List;


  
import org.apache.poi.hssf.usermodel.HSSFCell;  
import org.apache.poi.hssf.usermodel.HSSFRow;  
import org.apache.poi.hssf.usermodel.HSSFSheet;  
import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.assessment.entity.Staff;

public class  importStaff {
	
	  public   List<Staff> readStaff() throws IOException{  
		  	List<Staff> staffs=new ArrayList<Staff>();
		  	
	        FileInputStream inputStream = new FileInputStream(new File("d:\\poi\\测试.xls"));  
	        //读取工作簿  
	        HSSFWorkbook workBook = new HSSFWorkbook(inputStream);  
	        //读取工作表  
	        HSSFSheet sheet = workBook.getSheetAt(0);  
	        for (int i = 1; i < sheet.getLastRowNum()+1; i++) {
	        	Staff staff=new Staff();
	        	 HSSFRow row = sheet.getRow(i);  
				staff.setStaffName(row.getCell(0).getStringCellValue());
				if ("正常".equals(row.getCell(1).getStringCellValue())) {
					staff.setStaffState(1);
				}else{
					staff.setStaffState(2);
				}
				
				staff.setDirection(row.getCell(2).getStringCellValue());
				staff.setInterviewer(row.getCell(3).getStringCellValue());
				staff.setInterDept(row.getCell(4).getStringCellValue());
				if("男".equals(row.getCell(5).getStringCellValue())){
					staff.setStaffSex(1);
				}else{
					staff.setStaffSex(2);
				}				
				staff.setEmial(row.getCell(6).getStringCellValue());
				staff.setBirthdate(row.getCell(7).getDateCellValue());
				staff.setNativteplace(row.getCell(8).getStringCellValue());
				staff.setDegree(row.getCell(9).getStringCellValue());
				staff.setProfessional(row.getCell(10).getStringCellValue());
				staff.setSchool(row.getCell(11).getStringCellValue());
				staff.setGraduate(row.getCell(12).getDateCellValue());
				row.getCell(13).setCellType(CellType.STRING);
				staff.setTel(row.getCell(13).getStringCellValue());
				staff.setEntry(row.getCell(14).getDateCellValue());
				staffs.add(staff);
			} 
	        inputStream.close();  
	        workBook.close();//最后记得关闭工作簿  
			return staffs;
	    }  
}
